Example 08 : Creating a consignment with product information and allocating it
This example will create a single consignment in the DM system that contains product information about each parcel.
It will then allocate it to the best available service.
If the creation in DM fails for any reason (such as invalid postcodes), the service will respond with a fault code as an exception.
package com.metapack.dm.test; import com.metapack.deliverymanager.client.Address; import com.metapack.deliverymanager.client.Consignment; import com.metapack.deliverymanager.client.Parcel; import com.metapack.deliverymanager.client.Product; import com.metapack.deliverymanager.client.webservices.AllocationService; public class Example8 extends ExampleBase { public void run() throws Exception { AllocationService service = createAllocationService(); /* * Create an empty consignment object, and specify the order number. */ Consignment consignment = new Consignment(); consignment.setOrderNumber( "EXAMPLE-8" ); /* * Specify the warehouse, and the source address. Normally, the address is the * address of the warehouse, but not necessarily. All these pieces of information are required. */ consignment.setSenderCode("DEFAULT"); consignment.setSenderName("My default warehouse"); Address senderAddress = new Address(); senderAddress.setLine1( "12-14 Laystall Street" ); senderAddress.setLine2( "London" ); senderAddress.setCountryCode( "GBR" ); senderAddress.setPostCode( "EC1R 4PF" ); consignment.setSenderAddress( senderAddress ); /* * The destination. All these pieces of information are required. */ consignment.setRecipientName("Fransoise Hubert"); Address recipientAddress = new Address(); recipientAddress.setLine1( "1 Rue du Pont" ); recipientAddress.setLine2( "Paris" ); recipientAddress.setCountryCode( "FRA" ); recipientAddress.setPostCode( "12345" ); consignment.setRecipientAddress( recipientAddress ); /* * Now we specify the parcels (four, in this case). We will also record the information about * each parcel, including the 123 products inside the box. */ int parcelCount = 4; Parcel[] parcels = new Parcel [ parcelCount ]; for( int i = 0 ; i < parcelCount ; i++ ) { parcels[i] = new Parcel(); parcels[i].setNumber( i + 1 ); parcels[i].setParcelDepth(0.1); parcels[i].setParcelWidth(0.2); parcels[i].setParcelHeight(0.3); parcels[i].setParcelValue( 0.60 ); Product product = new Product(); product.setCountryOfOrigin( "FRA" ); product.setFabricContent( "FABRIC" ); product.setHarmonisedProductCode( "H_CODE" ); product.setProductCode( "PRODCODE" ); product.setProductDescription( "PROD_DESCRIPTION" ); product.setProductQuantity( 123 ); product.setProductTypeDescription( "PRODTYPE" ); product.setTotalProductValue( 99.12 ); product.setUnitProductWeight( 0.02 ); parcels[i].setProducts( new Product[] { product } ); } consignment.setParcelCount( parcelCount ); consignment.setParcels( parcels ); consignment.setConsignmentWeight( 1.56 ); /* * Create the consignments in DM */ Consignment[] createdConsignments = service.createAndAllocateConsignmentsWithBookingCode( new Consignment[] { consignment } , "TESTSTD" ); /* * Iterate through the responses to see what codes the consignments were given. In this example, * there should be only one. */ for( int i = 0 ; i < createdConsignments.length ; i++ ) { System.out.println( "Consignment " + createdConsignments[i].getOrderNumber() + " was created with code " + createdConsignments[i].getConsignmentCode() ); } } }

