At the beginning make instance of DHL rate request and set authentication information.
DHLRateRequest dhlRateRequest = new DHLRateRequest();
dhlRateRequest.Requestor.Id = "your id";
dhlRateRequest.Requestor.Password = "your password";
Create a DHL Shipment object and set most important variables on this object. Remember to assign additional authorization information.
DHLShipment dhlShipment = new DHLShipment();
dhlShipment.ShippingCredentials.AccountNbr = "your account number";
dhlShipment.ShippingCredentials.ShippingKey = "your shipping key";
Here we have most important part of shipment. Set sender and destination addresses. Check for correct zip code values, state and country.
dhlShipment.Sender.Address.Country = "US";
dhlShipment.Sender.Address.PostalCode = "33131";
dhlShipment.Sender.Address.State = "FL";
dhlShipment.Receiver.Address.Country = "US";
dhlShipment.Receiver.Address.PostalCode = "99501";
dhlShipment.Receiver.Address.State = "AK";
In shipment details you have to set service and / or some additional information.
DHLShipmentDetail shipmentDetails = new DHLShipmentDetail();
shipmentDetails.Service.ServiceCode = DHLServiceCode.Express;
dhlShipment.ShipmentDetail = shipmentDetails;
Shipment type and service determine total rate costs. Refer to DHL shipment services and shipment types for more information.
DHLShipmentType shipmentType = new DHLShipmentType();
shipmentType.ShipmentTypeCode = DHLShipmentTypeCode.Letter;
dhlShipment.ShipmentDetail.ShipmentType = shipmentType;
Set ship date. For example, today plus one day as shown below.
dhlShipment.ShipmentDetail.ShipDate = DateTime.Now.AddDays(1);
After shipment information has been specified, add this shipment to shipments collection. You can add more than one shipment, and send many shipments as one request.
dhlRateRequest.Shipments = new List<DHLShipment>();
dhlRateRequest.Shipments.Add(dhlShipment);
Make an instance of DHL rate and call Check(...) method to check rate costs. Then iterate through results and get any information you need.
DHLRateProvider rate = new DHLRateProvider();
DHLRateResponse dhlRates = rate.Check(dhlRateRequest, false);