Breaking

Wednesday, September 5, 2018

How to validate and create shipment using FedEx API in Dynamics Ax

Overview:

Validate Shipment is part of the Shipping service that allows customers to validate the accuracy of a shipment request prior to actually submitting the shipment transaction. This feature allows businesses that receive shipping orders from end-user customers to validate the shipment information prior to submitting a create shipment transaction to FedEx and printing a label. If for any reason the information needs to be edited or changed, it can be done while the end-user is still available to confirm the changes.

REGISTERING A FEDEX TEST ACCOUNT

To get started with FedEx, you need to register a FedEx test account:

 To do so:

Sign up at the FedEx Developer Resource Center and request a developer test key.
Once you have filled out the required form, the following will be mailed to you:
Ø  A test Key
Ø  A test Account
Ø  A test Meter Number
Ø  A test Password

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)


Validate Shipment Request Elements

Element
Description
RequestedShipment
Required
Describe ship information you wish to validate. For information on RequestedShipment elements, see Ship Service Coding Basics.
requestedShipment
/customsClearanceDetail/regulatoryControls
Valid values:
·        FOOD_OR_PERISHABLE - Required by FDA/BTA; must be true for food/perishable items coming to US or PR from non-US/non-PR origin.
·        NOT_APPLICABLE_FOR_LOW_CUSTOMS_VALUE_EXCEPTION - This indicates that the contents of this shipment are not applicable for a low customs value clearance exception. For example, US import FDA-regulated commodities are excluded from clearing under Section 321.
·        NOT_IN_FREE_CIRCULATION - Indicates that this shipment is Not in Free Circulation - primarily used within the EU.
RequestedShipment/
SpecialServicesRequested/
ShipmentDryIceDetail

requestedShipment/specialServicesRequested
/etdDetail/attributes
POST_SHIPMENT_UPLOAD_REQUESTED
This attribute indicates that the shipping client is requesting the ability to upload documents like the COMMERCIAL_INVOICE after the shipment has been processed. There may be some limitations on the window of time allowed for these uploads, so be sure that the ship date accurately indicates the date on which FedEx will take possession of the shipment.
RequestedPackageLineItem
/SpecialServicesRequested/Batterydetails
/BatteryClassificationDetail/material
Describes the material composition of the battery or cell.
Valid values:
·        LITHIUM_METAL
·        LITHIUM_ION
RequestedPackageLineItem
/SpecialServicesRequested/Batterydetails
/BatteryClassificationDetail/packing
Describes the packing arrangement of the battery or cell with respect to other items within the same package.
Valid values:
·        CONTAINED_IN_EQUIPMENT
·        PACKED_WITH_EQUIPMENT
RequestedPackageLineItem
/SpecialServicesRequested/Batterydetails
/BatteryClassificationDetail/regulatorySubType
A regulation specific classification for the battery or cell.
Valid value: IATA_SECTION_II
requestedShipment/specialServicesRequested
/specialServiceTypes
The types of all special services requested for the enclosing shipment (or other shipment-level transaction).
Valid values:
·        BLIND_SHIPMENT
·        BROKER_SELECT_OPTION
·        CALL_BEFORE_DELIVERY
·        COD
·        COD_REMITTANCE
·        CUSTOM_DELIVERY_WINDOW
·        CUT_FLOWERS
·        DANGEROUS_GOODS
·        DETENTION
·        DRY_ICE
·        EAST_COAST_SPECIAL
·        ELECTRONIC_TRADE_DOCUMENTS
·        EVENT_NOTIFICATION
·        EXCLUDE_FROM_CONSOLIDATION
·        EXCLUSIVE_USE
·        EXHIBITION_DELIVERY
·        EXHIBITION_PICKUP
·        EXPEDITED_ALTERNATE_DELIVERY_ROUTE
·        EXPEDITED_ONE_DAY_EARLIER
·        EXPEDITED_SERVICE_MONITORING_AND_DELIVERY
·        EXPEDITED_STANDARD_DAY_EARLY_DELIVERY
·        EXTRA_LABOR
·        FEDEX_ONE_RATE
·        FUTURE_DAY_SHIPMENT
·        HOLD_AT_LOCATION
·        HOLIDAY_DELIVERY
·        HOLIDAY_GUARANTEE
·        HOME_DELIVERY_PREMIUM
·        INTERNATIONAL_CONTROLLED_EXPORT_SERVICE
·        INTERNATIONAL_MAIL_SERVICE
·        INTERNATIONAL_TRAFFIC_IN_ARMS_REGULATIONS
·        MARKING_OR_TAGGING
·        NON_BUSINESS_TIME
·        PALLETS_PROVIDED
·        PENDING_COMPLETE
·        PENDING_SHIPMENT
·        PERMIT
·        PHARMACY_DELIVERY
·        PRE_DELIVERY_NOTIFICATION
·        PRE_EIG_PROCESSING
·        PRE_MULTIPLIER_PROCESSING
·        REGIONAL_MALL_DELIVERY
·        REGIONAL_MALL_PICKUP
·        RETURN_SHIPMENT
·        RETURNS_CLEARANCE
·        RETURNS_CLEARANCE_SPECIAL_ROUTING_REQUIRED
·        SATURDAY_DELIVERY
·        SATURDAY_PICKUP
·        SHIPMENT_ASSEMBLY
·        SORT_AND_SEGREGATE
·        SPECIAL_DELIVERY
·        SPECIAL_EQUIPMENT
·        STORAGE
·        SUNDAY_DELIVERY
·        THIRD_PARTY_CONSIGNEE
·        USPS_DELIVERY
·        USPS_PICKUP
·        WEIGHING
RequestedShipment/
RequestedPackageLineItems/
SpecialServicesRequested/
DangerousGoodsDetail/
UploadedTrackingNumber
UploadedTrackingNumber element is used to identify an instance of an uploaded dangerous goods handling unit. This element is required only if you have already validated DG data using a FedEx DG Ready solution (fedex.com/dgready) or have coded a proprietary integration using the FedEx provided Dangerous Goods / Hazardous Materials information upload option.
requestedShipment/shipper/address
/geographicCoordinates
The geographic coordinates corresponding to this address.
ISO6709GeographicCoordinates
RequestedShipment
/ShippingDocumentSpecification
/FreightAddressLabelDetail/DocTabContent
/DocTabContentType
Valid values are:
·        BARCODED
·        CUSTOM
·        MINIMUM
·        STANDARD
·        ZONE001
RequestedShipment
/ShippingDocumentSpecification
/CustomDocumentDetail
Data required to produce a custom-specified document, either at shipment or package level.
CustomDocumentDetail/Format
Common information controlling document production.
CustomDocumentDetail/
LabelPrintingOrientation
Applicable only to documents produced on thermal printers with roll stock.
CustomDocumentDetail/LabelRotation
Applicable only to documents produced on thermal printers with roll stock.
CustomDocumentDetail/SpecificationId
Identifies the formatting specification used to construct this custom document.
CustomDocumentDetail/
CustomDocumentIdentifier
Identifies the individual document specified by the client.
CustomDocumentDetail/DocTabContent
If provided, thermal documents will include specified doc tab content. If omitted, document will be produced without doc tab content.
CustomDocumentDetail/CustomLabelDetail
This allows the customer to define how custom information is to be positioned and formatted on a custom label or the customizable portion of a shipping label, and what the custom information should be.
CustomLabelDetail/CoordinateUnits
Valid values are:
·        MILS (thousanths of an inch)
·        PIXELS (device-dependent)
CustomLabelDetail/TextEntries
Constructed string, based on format and zero or more data fields, printed in specified printer font (for thermal labels) or generic font/size (for plain paper labels).
CustomLabelDetail/GraphicEntries
Image to be included from printer's memory, or from a local file for offline clients.
CustomLabelDetail/BoxEntries
Solid (filled) rectangular area on label.
CustomLabelDetail/CustomLabelTextBoxEntry
Constructed string, based on format and zero or more data fields, printed in specified printer font (for thermal labels) or generic font/size (for plain paper labels).
CustomLabelTextBoxEntry/TopLeftCorner
Horizontal and vertical position, relative to left edge of custom area.
CustomLabelTextBoxEntry/BottomRightCorner
Horizontal and vertical position, relative to left edge of custom area.
CustomLabelTextBoxEntry/Position
Horizontal and vertical position, relative to left edge of custom area.
CustomLabelTextBoxEntry/Format
Format
CustomLabelTextBoxEntry/DataFields
Data fields
CustomLabelTextBoxEntry/ThermalFontId
Printer-specific font name for use with thermal printer labels.
CustomLabelTextBoxEntry/FontName
Generic font name for use with plain paper labels.
CustomLabelTextBoxEntry/FontSize
Generic font size for use with plain paper labels.
CustomLabelTextBoxEntry/Rotation
Describes the rotation of an item from its default orientation.
Valid values are:
·        NONE
·        RIGHT
·        UPSIDE_DOWN
CustomLabelDetail/BarcodeEntries
Constructed string, based on format and zero or more data fields, printed in specified barcode symbology.
RequestedShipment/LabelSpecification/
CustomerSpecifiedLabelDetail/
LabelMaskableDataType
Names of data elements/areas which may be suppressed from printing on labels.
·        CUSTOMS_VALUE
·        DUTIES_AND_TAXES_PAYOR_ACCOUNT_NUMBER
·        SECONDARY_BARCODE
·        SHIPPER_ACCOUNT_NUMBER
·        TERMS_AND_CONDITIONS
·        TRANSPORTATION_CHARGES_PAYOR_ACCOUNT_NUMBER
LabelSpecification/dispositions/storageDetail /type 
Optional
Indicates how this requested shipping document should be stored
Valid values
·        ASYNC_SERVICE (store in the asynchronous service for later retrieval)
·        LOCAL_FILE_SYSTEM (store as a file in the local filesystem for later retrieval)
RequestedShipment/
SmartPostShipmentDetail/
SmartPostShipmentProcessing
OptionsRequested
Through this option, an existing SmartPost small shipper or return shipper can specify to have the Ground tracking number provided in the shipment reply. This is a contingency feature in case the customer requires the Ground tracking number for internal processes or for tracking SmartPost shipments.
The Ground tracking number will only be provided for existing SmartPost small shippers or return shippers. Customers will have the same reporting and tracking capabilities as today when they receive a Ground tracking number. However, the Ground tracking number will not be printed on the FXSP shipping label.
fedex.com provides the same tracking visibility for SmartPost shipments when using either the SmartPost tracking number or the Ground tracking number.
Fedex recommends using fedex.com, rather than USPS.com, for all tracking activities for SmartPost shipments.
RequestedShipment/
SmartPostShipmentDetail/
SmartPostShipmentProcessing
OptionsRequested/
SmartPostShipmentProcessing
OptionType
Valid values:
·         GROUND_TRACKING_NUMBER_REQUESTED
RequestedShipment/
RequestedPackageLineItem/
PackageSpecialServicesRequested/
DangerousGoodsDetail/
DangerousGoodsContainer/
HazardousCommodityContent/
NetExplosiveDetail
The total mass of the contained explosive substances, without the mass of any casings, bullets, shells, etc.
RequestedPackageLineItem/
PackageSpecialServicesRequested/
DangerousGoodsDetail/
DangerousGoodsContainer
/HazardousCommodityContent/
NetExplosiveDetail/
NetExplosiveClassificationType
Valid values:
·        NET_EXPLOSIVE_CONTENT
·        NET_EXPLOSIVE_MASS
·        NET_EXPLOSIVE_QUANTITY
·        NET_EXPLOSIVE_WEIGHT

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 IND_FedExRateService.RequestedPackageLineItem();
dim                           = new IND_FedExRateService.Dimensions();
weight                        = new IND_FedExRateService.Weight();
money                         = new IND_FedExRateService.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/Ship");
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 Tracking number, Net Weight along with the remaining information like below.
Please find the below object which you will get in reply from the FedEx API for Shipment create.
please download below file for get response from FedEx API and get the data from the service.
Get Response from FedEx API Service

No comments:

Post a Comment

Thanks for your comment.