Customers examples
Below are examples of simple applications running the method responsible for creating a shipment and booking a courier, written in .NET and JAVA.
.NET
- Open the "Visual Studio Command Prompt” console.
- Run command
wsdl https://dhl24.com.pl/webapi2 - For a project in Visual Studio, add the generated DHL24WebapiService.cs file
- Add to the project the System.Web.Services library
- All done
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace DHL24Example { internal class Program { private static void Main(string[] args) { DHL24WebapiService service = new DHL24WebapiService(); Console.WriteLine("AuthData..."); AuthData auth = new AuthData(); auth.username = "testomir"; auth.password = "testalski"; Console.WriteLine("CreateShipmentRequest..."); CreateShipmentRequest request = new CreateShipmentRequest(); request.content = "Gra komputerowa"; request.shipmentInfo = new ShipmentInfo(); request.shipmentInfo.serviceType = "AH"; request.shipmentInfo.dropOffType = "REGULAR_PICKUP"; request.shipmentInfo.labelType = "LP"; request.shipmentInfo.shipmentTime = new ShipmentTime(); request.shipmentInfo.shipmentTime.shipmentDate = "2012-11-13"; request.shipmentInfo.shipmentTime.shipmentStartHour = "12:00"; request.shipmentInfo.shipmentTime.shipmentEndHour = "15:00"; request.shipmentInfo.billing = new Billing(); request.shipmentInfo.billing.shippingPaymentType = "SHIPPER"; request.shipmentInfo.billing.paymentType = "BANK_TRANSFER"; request.shipmentInfo.billing.billingAccountNumber = 1234567; request.pieceList = new Package[] { new Package() }; request.pieceList[0].packageType = "ENVELOPE"; request.pieceList[0].quantity = 1; request.ship = new Ship(); request.ship.shipper = new Addressat(); request.ship.shipper.address = new Address(); request.ship.shipper.address.name = "Janek Kowalski"; request.ship.shipper.address.postalCode = "00909"; request.ship.shipper.address.city = "Warszawa"; request.ship.shipper.address.street = "Leśna"; request.ship.shipper.address.houseNumber = "9"; request.ship.receiver = new Addressat(); request.ship.receiver.address = new Address(); request.ship.receiver.address.name = "Karol Bielecki"; request.ship.receiver.address.postalCode = "02796"; request.ship.receiver.address.city = "Warszawa"; request.ship.receiver.address.street = "Wąwozowa"; request.ship.receiver.address.houseNumber = "2"; request.ship.receiver.address.apartmentNumber = "59"; Console.WriteLine("call createShipment()..."); CreateShipmentResponse response = service.createShipment(auth, request); Console.WriteLine("save response label to file..."); byte[] pdfContent = Convert.FromBase64String(response.label.labelContent); File.WriteAllBytes("result.pdf", pdfContent); Console.WriteLine("end!"); } } }
JAVA
- Download and unzip the apache-cxf tool
- Run command:
wsdl2java -autoNameResolution https://dhl24.com.pl/webapi2 - Copy the generated sources to the project directory
- Add the jar libraries from the apache-cxf-x.y.z\lib\endorsed directory to the project
- All done
package pl._3e.examples; import java.io.FileOutputStream; import java.io.IOException; import javax.xml.bind.DatatypeConverter; import pl.com.dhl24.webapi.provider.service.Address; import pl.com.dhl24.webapi.provider.service.Addressat; import pl.com.dhl24.webapi.provider.service.ArrayOfPackage; import pl.com.dhl24.webapi.provider.service.AuthData; import pl.com.dhl24.webapi.provider.service.Billing; import pl.com.dhl24.webapi.provider.service.CreateShipmentRequest; import pl.com.dhl24.webapi.provider.service.CreateShipmentResponse2; import pl.com.dhl24.webapi.provider.service.Package; import pl.com.dhl24.webapi.provider.service.Ship; import pl.com.dhl24.webapi.provider.service.ShipmentInfo; import pl.com.dhl24.webapi.provider.service.ShipmentTime; import pl.com.dhl24.webapi.provider.service_html_ws_1.DHL24WebapiPort; import pl.com.dhl24.webapi.provider.service_html_ws_1.DHL24WebapiService; public class Dhl24Example { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { final DHL24WebapiPort service = new DHL24WebapiService().getDHL24WebapiPort(); System.out.println("AuthData..."); final AuthData auth = new AuthData(); auth.setUsername("testomir"); auth.setPassword("testalski"); System.out.println("CreateShipmentRequest..."); final CreateShipmentRequest request = new CreateShipmentRequest(); request.setContent("Gra komputerowa"); request.setShipmentInfo(new ShipmentInfo()); request.getShipmentInfo().setServiceType("AH"); request.getShipmentInfo().setDropOffType("REGULAR_PICKUP"); request.getShipmentInfo().setLabelType("LP"); request.getShipmentInfo().setShipmentTime(new ShipmentTime()); request.getShipmentInfo().getShipmentTime().setShipmentDate("2012-11-13"); request.getShipmentInfo().getShipmentTime().setShipmentStartHour("12:00"); request.getShipmentInfo().getShipmentTime().setShipmentEndHour("15:00"); request.getShipmentInfo().setBilling(new Billing()); request.getShipmentInfo().getBilling().setShippingPaymentType("SHIPPER"); request.getShipmentInfo().getBilling().setPaymentType("BANK_TRANSFER"); request.getShipmentInfo().getBilling().setBillingAccountNumber(1234567); final Package pkg = new Package(); pkg.setType("ENVELOPE"); pkg.setQuantity(1); request.setPieceList(new ArrayOfPackage()); request.getPieceList().getItem().add(pkg); request.setShip(new Ship()); request.getShip().setShipper(new Addressat()); request.getShip().getShipper().setAddress(new Address()); request.getShip().getShipper().getAddress().setName("Janek Kowalski"); request.getShip().getShipper().getAddress().setPostalCode("00909"); request.getShip().getShipper().getAddress().setCity("Warszawa"); request.getShip().getShipper().getAddress().setStreet("Leśna"); request.getShip().getShipper().getAddress().setHouseNumber("9"); request.getShip().setReceiver(new Addressat()); request.getShip().getReceiver().setAddress(new Address()); request.getShip().getReceiver().getAddress().setName("Karol Bielecki"); request.getShip().getReceiver().getAddress().setPostalCode("02796"); request.getShip().getReceiver().getAddress().setCity("Warszawa"); request.getShip().getReceiver().getAddress().setStreet("Wąwozowa"); request.getShip().getReceiver().getAddress().setHouseNumber("2"); request.getShip().getReceiver().getAddress().setApartmentNumber("59"); System.out.println("call createShipment()..."); final CreateShipmentResponse2 response = service.createShipment(auth, request); System.out.println("save response label to file..."); final byte[] content = DatatypeConverter.parseBase64Binary(response.getLabel().getLabelContent()); final FileOutputStream file = new FileOutputStream("result.pdf", false); file.write(content, 0, content.length); file.close(); System.out.println("end!"); } }Go back to topic list