Breaking

Thursday, September 6, 2018

How to get Package Rates from FedEx in Dynamics Ax 2012

Overview:

In This section we will get Package Rates using FedEx API service. Which we have created in previous section. As you know we have get Account Number, Meter Number, Asses Key, Password and URL from the FedEx. So using this credentials we will get Package Rates from the FedEx. We need credentials because of every request FedEx check for which Account Number and Meter Number has to Response for which URL, which we will pass in the Rates Request.

So let’s start and get package rates from the FedEx API using the Rate Request API. Here I have create simple job to get Package rates from the FedEx. Before that you need to understand what is Package? And how to create package.

Package is nothing but your items collection which will pack your items in one container. You can create multiple container and create package. FedEx has some limitation for Package and container type, there are dimensions which has defined in the package, so you need to identify the combination of the dimension and request to FedEx service for getting the package Rates.

There are multiple dimension like weight, height, length, volume. Which will check for when you pack your items in the container. Here is the calculation of how to calculate the girth and length of your package.

Calculate the length & girth of your parcel manually

To calculate the girth of a package, follow these guidelines:

1. Measure the three parcel dimensions in centimetres.
Example: 50 cm (Length) x 40 cm (Width) x 30 cm (Height).

2. Add the measurements of the two smallest dimensions together. Multiply the result by two. This is the girth of your package.
Example: 40 cm (Width) + 30 cm (Height) = 70 cm. 70 cm x 2 = 140 cm (Girth).

3. Now simply take the longest dimension and add this to the package girth. The result is the combined length and girth of your parcel.
Example: 50 cm (Length) + 140 cm (Girth) = 190 cm (Combined Length and Girth)


Now create a code to get the Package rate from FedEx. Here I have given an example of the Rate request how to set parameter in the request. Which will calculate the Rate and response you back in the Reply details.

Which objects you have to set in the rate request, you need to set the web authentication details, Shipper details, recipients details, line items details with the dimensions, transaction details, version details, client details, request URL. There are many types in the Package, Service, Dropoff you need to set valid types in this parameter otherwise you will not able to get rates from the FedEx.

Please check below list for the ServiceType, DropoffType and PackageType.

1.    List of Service Types in FedEx
2.    List of Package Types in FedEx
3.    List of Dropoff Types in FedEx

To set the set the web authentication details, Shipper details, recipient’s details, line items details with the dimensions, transaction details, version details, client details, request URL, ServiceType, DropofTypes and PackageTypes please use the below code in your job.
//WebAuthenticationCredentials
webAuthenticationCred.set_Key(#testKey);
webAuthenticationCred.set_Password(#password);
webAuthenticationDetail.set_UserCredential(webAuthenticationCred);
rateRequest.set_WebAuthenticationDetail(webAuthenticationDetail);

//ClientDetail
clientDetail.set_AccountNumber(#clientAccNo);
clientDetail.set_MeterNumber(#clientMeterNo);
rateRequest.set_ClientDetail(clientDetail);

//Version
rateRequest.set_Version(versionId);

rateRequest.set_ReturnTransitAndCommit(true);
rateRequest.set_ReturnTransitAndCommitSpecified(true);

//transction
transactionDetail.set_CustomerTransactionId("***Rate Request using AX***");
rateRequest.set_TransactionDetail(transactionDetail);

//Shipper
shipperrAddress = new IND_FedExRateService.Address();
streetLines.SetValue(#shipperStreetLine,0);
shipperrAddress.set_StreetLines(streetLines);
shipperrAddress.set_City(#shipperCity);
shipperrAddress.set_CountryCode(#shipperCountryCode);
shipperrAddress.set_PostalCode(#shipperPostalcode);
shipperrAddress.set_StateOrProvinceCode(#shipperStateOrProvince);
shipmentDetails.set_Address(shipperrAddress);
requestShipment.set_Shipper(shipmentDetails);

//Recipient
recipientAddress = new IND_FedExRateService.Address();
streetLines.SetValue(#recipientStreetLine,0);
recipientAddress.set_StreetLines(streetLines);
recipientAddress.set_City(#recipientCity);
recipientAddress.set_CountryCode(#recipientCountryCode);
recipientAddress.set_PostalCode(#recipientPostalcode);
recipientAddress.set_StateOrProvinceCode(#recipientStateOrProvince);
recipientDetails.set_Address(recipientAddress);
requestShipment.set_Recipient(recipientDetails);

//PackageLineDetails
lineItem                      = new FedExRateServiceRef.RequestedPackageLineItem();
dim                           = new FedExRateServiceRef.Dimensions();
weight                        = new FedExRateServiceRef.Weight();
money                         = new FedExRateServiceRef.Money();

dim.set_Height("10");
dim.set_Width("12");
dim.set_Length("9");
dim.set_Units(FedExRateServiceRef.LinearUnits::IN);
dim.set_UnitsSpecified(true);
lineItem.set_Dimensions(dim);

weight.set_Units(FedExRateServiceRef.WeightUnits::LB);
weight.set_UnitsSpecified(true);
weight.set_Value(1.0);
weight.set_ValueSpecified(true);
lineItem.set_Weight(weight);

lineItem.set_GroupPackageCount("1");
lineItem.set_SequenceNumber(int2str(i));
lineItems.SetValue(lineItem,1);

requestShipment.set_RequestedPackageLineItems(lineItems);
requestShipment.set_PackageCount("1");

requestShipment.set_ServiceType(FedExRateServiceRef.ServiceType::INTERNATIONAL_PRIORITY);
requestShipment.set_PackagingType(FedExRateServiceRef.PackagingType::YOUR_PACKAGING);
requestShipment.set_ShipTimestamp(systemDateGet());
requestShipment.set_DropoffType(FedExRateServiceRef.DropoffType::REGULAR_PICKUP);
requestShipment.set_ServiceTypeSpecified(true);
requestShipment.set_PackagingTypeSpecified(true);
requestShipment.set_ShipTimestampSpecified(true);
requestShipment.set_DropoffTypeSpecified(true);

raterequest.set_RequestedShipment(requestShipment);
rateservice.set_Url("https://wsbeta.fedex.com:443/web-services/rate");
After you will get the response from the FedEx API which has SUCCESS or FAILURE. If you get SUCCESS notification from the FedEx API then it will also response the Net Weight along with the remaining information like below.

No comments:

Post a Comment

Thanks for your comment.