DHL Tracking

Tracking functionality of Supreme Tracking component is very easy to use. There is no need to care about services, packaging types and much of the information you need for rating functionality. All you need to do is make a request object, set authentication information to it, add tracking numbers and check for response. Here is an example of DHL tracking.

 

Create request and authorization ticket objects. 

DHLAuthTicket dhlAuthTicket = new DHLAuthTicket("user", "passwd");

DHLTrackRequest trackRequest = new DHLTrackRequest();

 

Add tracking number(s) to request. 

 

trackRequest.TrackingNumbers.Add("49132407380"); 

DHLTrackResponse dhlTrackResponse = null; 

 

Check for tracking response and get any tracking information you need.  

 

DHLTrackProvider dhlTracking = new DHLTrackProvider();

 

string senderCity = dhlTrackResponse.Shipments[0].Sender.City;

string reciverCity = dhlTrackResponse.Shipments[0].Receiver.City;

 

Check for any errors. 

 

if (dhlTrackResponse.Faults != null && dhlTrackResponse.Faults.Items.Count > 0)

    /* usually it means that there is no any shipment at response */

    foreach (DHLGeneralFault dhlGenFault in dhlTrackResponse.Faults.Items)

    {

        string errorCode = dhlGenFault.Code;

        string description = dhlGenFault.Description;

    }

 

Iterate through DHL shipment and get more info. 

 

foreach (DHLTrackedShipment shipment in dhlTrackResponse.Shipments)

    /* check for any errors related to given track number */

    if (shipment.Faults != null && shipment.Faults.Items.Count > 0)

    {

        foreach (DHLShipmentFault shipmentFault in shipment.Faults.Items)

        {

            string errorCode = shipmentFault.Code;

            string description = shipmentFault.Description;

        }

        /* usually it means that there is no tracking history */

        continue;

    }

    /* iterate through track statuses*/

    foreach (DHLTrackStatus trackStatus in shipment.TrackingHistory.Statuses)

    {

        /* get more info related to this track number */

        string Country = trackStatus.Location.Country;

        string City = trackStatus.Location.City;

        string IsFinalDelivery = trackStatus.FinalDelivery;

        DHLDate date = trackStatus.Date;

    }