Example 27 : Create consignment with product information

Printer-friendly version
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.ConsignmentService;
 
public class Example27 extends ExampleBase {
 
	public void run() throws Exception {
		ConsignmentService service = createConsignmentService();
 
		/*
		 * Create an empty consignment object, and specify the order number.
		 */
 
		Consignment consignment = new Consignment();
		consignment.setOrderNumber( "EXAMPLE-27" );
 
		/*
		 * 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("The Queen");
		Address recipientAddress = new Address();
		recipientAddress.setLine1( "Buckingham Palace" );
		recipientAddress.setLine2( "London" );
		recipientAddress.setCountryCode( "GBR" );
		recipientAddress.setPostCode( "SW1A 1AA" );
		consignment.setRecipientAddress( recipientAddress );
 
		/*
		 * Now we specify how many parcels there are, and specify the consignment weight.
		 * Both of these are mandatory. NB. We have also passed in an array of four parcels.
		 * Even if you don't supply information at the parcel level, you need to do this.
		 */
 
		consignment.setConsignmentLevelDetailsFlag( false );
 
		Parcel parcel1 = new Parcel();
		parcel1.setDutyPaid( 1.23 );
 
		parcel1.setParcelWeight( 0.6 );
 
		parcel1.setParcelDepth( 0.21 );
		parcel1.setParcelHeight( 0.33 );
		parcel1.setParcelWidth( 0.48 );
 
		parcel1.setParcelValue( 5.99 );
 
		Product product1a = new Product();
		product1a.setCountryOfOrigin( "GBR" );
		product1a.setFabricContent( "Linen" );
		product1a.setHarmonisedProductCode( "HCODE8761" );
		product1a.setProductCode( "SKU-7124356123" );
		product1a.setProductDescription( "Lightbulbs" );
 
		consignment.setParcelCount( 1 );
		consignment.setParcels( new Parcel[] { parcel1 } );
		consignment.setConsignmentWeight( 1.56 );
 
		/*
		 * Create the consignments in DM
		 */
 
		Consignment[] createdConsignments = service.createConsignments( new Consignment[] { consignment } );
 
		/*
		 * 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() );
		}
	}
}