package test;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.xml.soap.SOAPException;
import java.net.URL;
import org.apache.axis.AxisFault;
import
com.dpd.common.service.types.Authentication._2_0.AuthenticationFault;
import
com.dpd.common.service.LoginService._2_0.*;
import
com.dpd.common.service.types.LoginService._2_0.*;
import
com.dpd.common.service.ShipmentService._4_4.*;
import
com.dpd.common.service.types.ShipmentService._4_4.*;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.Constants;
import org.apache.axis.client.Stub;
import org.apache.axis.encoding.Base64;
import java.io.FileOutputStream;
import java.io.IOException;
public class ShipmentService44_storeOrders {
public static void main(String[] args) throws SOAPException, IOException {
LoginServiceProxy myApiSoapClient = new LoginServiceProxy();
Login myLogin = new Login();
try {
myLogin = myApiSoapClient.getAuth("xxx", "xxx", "de_DE");
} catch (RemoteException ex) {
if (ex instanceof AxisFault) {
if (ex instanceof AuthenticationFault) {
System.out.println("FAULT CODE Login Service 2.0: " + ((AuthenticationFault) ex).getErrorCode());
System.out.println("FAULT STRING Login Service 2.0: " + ((AuthenticationFault) ex).getErrorMessage());
}
}
}
// printOptions
PrintOption[] myPrintOptionList = new PrintOption[1];
PrintOption myPrintOption = new PrintOption();
myPrintOption.setPaperFormat(
com.dpd.common.service.types.ShipmentService._4_4.PrintOptionPaperFormat.A4);
myPrintOption.setStartPosition(
com.dpd.common.service.types.ShipmentService._4_4.StartPosition.UPPER_LEFT);
myPrintOption.setOutputFormat(
com.dpd.common.service.types.ShipmentService._4_4.OutputFormatType.PDF);
myPrintOptionList[0] = myPrintOption;
PrintOptions myPrintOptions = new PrintOptions();
myPrintOptions.setSplitByParcel(false);
myPrintOptions.setPrintOption(myPrintOptionList);
// order (1-30)
ShipmentServiceData[] DPDOrderDataList = new ShipmentServiceData[1];
DPDOrderDataList[0] = new ShipmentServiceData();
// ----------- generalShipmentData
GeneralShipmentData myGeneralShipmentData = new GeneralShipmentData();
myGeneralShipmentData.setMpsCustomerReferenceNumber1("Article 123");
myGeneralShipmentData.setMpsCustomerReferenceNumber2("Order 456");
myGeneralShipmentData.setIdentificationNumber("Article 456");
myGeneralShipmentData.setSendingDepot("0190");
myGeneralShipmentData.setProduct(GeneralShipmentDataProduct.CL);
myGeneralShipmentData.setMpsWeight(500);
// ---------------------- sender
AddressWithType mySender = new AddressWithType();
mySender.setName1("Matratzen Direct AG");
mySender.setName2("Christoph Bong");
mySender.setStreet("Max-Planck-Str.");
mySender.setHouseNo("35");
mySender.setState(null);
mySender.setCountry("DE");
mySender.setZipCode("50858");
mySender.setCity("Köln, Junkersdorf");
mySender.setCustomerNumber("");
mySender.setContact("");
mySender.setPhone("+491786787676");
myGeneralShipmentData.setSender(mySender);
// ---------------------- recipient
AddressWithType myRecipient = new AddressWithType();
myRecipient.setName1("DPD Deutschland GmbH");
myRecipient.setName2("");
myRecipient.setStreet("Wailandtstr.");
myRecipient.setHouseNo("1");
myRecipient.setState(null);
myRecipient.setCountry("DE");
myRecipient.setZipCode("63741");
myRecipient.setCity("Aschaffenburg");
myRecipient.setCustomerNumber("");
myRecipient.setContact("");
myRecipient.setPhone("");
myGeneralShipmentData.setRecipient(myRecipient);
DPDOrderDataList[0].setGeneralShipmentData(myGeneralShipmentData);
// ----------- parcels
Parcel[] myParcelList = new Parcel[1];
Parcel myParcel = new Parcel();
myParcel.setCustomerReferenceNumber1("Article 123");
myParcel.setCustomerReferenceNumber2("Order 456");
myParcel.setWeight(500);
myParcel.setContent("Smartphones");
myParcelList[0] = myParcel;
DPDOrderDataList[0].setParcels(myParcelList);
// ----------- productAndServiceData
ProductAndServiceData myProductAndServiceData = new ProductAndServiceData();
myProductAndServiceData.setOrderType(ProductAndServiceDataOrderType.value1);
// ---------------------- pickup
Pickup myPickup = new Pickup();
myPickup.setTour(0);
myPickup.setQuantity(1);
myPickup.setDate(20230803);
myPickup.setFromTime1("1300");
myPickup.setToTime1("1700");
myPickup.setExtraPickup(1);
// --------------------------------- collectionrequestaddress
Address myCollectionRequestAddress = new Address();
myCollectionRequestAddress.setName1("Matratzen Direct AG");
myCollectionRequestAddress.setName2("Christoph Bong");
myCollectionRequestAddress.setStreet("Max-Planck-Str.");
myCollectionRequestAddress.setHouseNo("35");
myCollectionRequestAddress.setState(null);
myCollectionRequestAddress.setCountry("DE");
myCollectionRequestAddress.setZipCode("50858");
myCollectionRequestAddress.setCity("Köln, Junkersdorf");
myCollectionRequestAddress.setCustomerNumber("");
myCollectionRequestAddress.setContact("");
myCollectionRequestAddress.setPhone("+491786787676");
myPickup.setCollectionRequestAddress(myCollectionRequestAddress);
myProductAndServiceData.setPickup(myPickup);
// ---------------------- predict
Notification myNotification = new Notification();
myNotification.setChannel(NotificationChannel.value1);
myNotification.setValue("m.mustermann@dpd.de");
myNotification.setLanguage("DE");
myProductAndServiceData.setPredict(myNotification);
DPDOrderDataList[0].setProductAndServiceData(myProductAndServiceData);
// storeOrders
StoreOrders myStoreOrders = new StoreOrders();
myStoreOrders.setPrintOptions(myPrintOptions);
myStoreOrders.setOrder(DPDOrderDataList);
// RESPONSE
try {
URL myEndpointURL = new
URL("https://public-ws-stage.dpd.com/services/ShipmentService/V4_4/");
ShipmentServicePublic_4_4Locator myShipmentService44Locator = new ShipmentServicePublic_4_4Locator();
ShipmentServicePublic_4_4_SOAPStub myShipmentService44Webservice = new ShipmentServicePublic_4_4_SOAPStub(
myEndpointURL, myShipmentService44Locator);
Stub myStub = (Stub) myShipmentService44Webservice;
SOAPHeaderElement header = new SOAPHeaderElement("http://dpd.com/common/service/types/Authentication/2.0",
"authentication") {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void setAttribute(String namespace, String localName, String value) {
if (!Constants.ATTR_MUST_UNDERSTAND.equals(localName)) {
super.setAttribute(namespace, localName, value);
}
}
};
MessageElement myDelisIDElement = new MessageElement();
myDelisIDElement.setName("delisId");
myDelisIDElement.setValue("sandboxdpd");
header.addChild(myDelisIDElement);
MessageElement myAuthTokenElement = new MessageElement();
myAuthTokenElement.setName("authToken");
myAuthTokenElement.setValue(myLogin.getAuthToken());
header.addChild(myAuthTokenElement);
MessageElement myMessageLanguage = new MessageElement();
myMessageLanguage.setName("messageLanguage");
myMessageLanguage.setValue("de_DE");
header.addChild(myMessageLanguage);
header.setActor(null);
myStub.setHeader(header);
// storeOrders
StoreOrdersResponse myStoreOrdersResponse = new StoreOrdersResponse();
myStoreOrdersResponse = myShipmentService44Webservice.storeOrders(myStoreOrders);
StoreOrdersResponseType myStoreOrdersResponseType = new StoreOrdersResponseType();
myStoreOrdersResponseType = myStoreOrdersResponse.getOrderResult();
List<ShipmentResponse> myShipmentResponseList = new ArrayList<ShipmentResponse>();
myShipmentResponseList = Arrays.asList(myStoreOrdersResponseType.getShipmentResponses());
if (myShipmentResponseList != null && myShipmentResponseList.size() > 0) {
for (ShipmentResponse item : myShipmentResponseList) {
if (item.getFaults() != null) {
// Error Handling
for (FaultCodeType myFault : item.getFaults()) {
System.out.println("FAULT CODE Shipment Service 4.3: " + myFault.getFaultCode());
System.out.println("FAULT STRING Shipment Service 4.3: " + myFault.getMessage() + "\n\n");
}
}
{
// Label PDF
if (myStoreOrdersResponseType.getOutput() != null) {
String myBase64PDF = new String(Base64.encode(myStoreOrdersResponseType.getOutput().getContent()));
System.out.println("Base64 PDF String: " + myBase64PDF + "\n\n");
byte[] pdf_bytes = myStoreOrdersResponseType.getOutput().getContent();
FileOutputStream fos = new FileOutputStream(
"C://Users/.../Desktop/Test-PDF.pdf");
fos.write(pdf_bytes);
fos.close();
}
System.out.println("identificationNumber: " + item.getIdentificationNumber());
System.out.println("mpsId: " + item.getMpsId());
for (ParcelInformationType myParcelInformation : item.getParcelInformation()) {
System.out.println("parcelLabelNumber: " + myParcelInformation.getParcelLabelNumber());
}
}
}
}
} catch (RemoteException ex) {
System.out.println(ex.toString());
if (ex instanceof AxisFault) {
if (ex instanceof AuthenticationFault) {
System.out.println("FAULT CODE Shipment Service 4.4: " + ((AuthenticationFault) ex).getErrorCode());
System.out.println("FAULT STRING Shipment Service 4.4: " + ((AuthenticationFault) ex).getErrorMessage());
}
}
}
}
}