Example 65 : Create PDFs for consignment
This example shows how to create all of the PDFs for a consignment including documentation (if required).
package com.metapack.dm.test; import java.io.FileOutputStream; import com.metapack.deliverymanager.client.Address; import com.metapack.deliverymanager.client.Consignment; import com.metapack.deliverymanager.client.Labels; import com.metapack.deliverymanager.client.Parcel; import com.metapack.deliverymanager.client.Product; import com.metapack.deliverymanager.client.webservices.AllocationService; import com.metapack.deliverymanager.client.webservices.ConsignmentService; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; public class Example65 extends ExampleBase { public void run() throws Exception { Consignment consignment = createDefaultConsignment( "EXAMPLE-65" , 3 ); consignment.setConsignmentLevelDetailsFlag( false ); Address address = new Address(); address.setLine1("1234 Tasteless Mansion Avenue"); address.setLine2("Beverly Hills"); address.setLine3(""); address.setLine4(""); address.setPostCode("CA 90210"); address.setCountryCode("USA"); consignment.setRecipientAddress( address ); Product product1a = new Product(); product1a.setCountryOfOrigin( "GBR" ); product1a.setFabricContent( "Linen" ); product1a.setHarmonisedProductCode( "HCODE8761" ); product1a.setProductCode( "SKU-7124356123" ); product1a.setProductDescription( "Lightbulbs" ); product1a.setProductQuantity( 6 ); Product product1b = new Product(); product1b.setCountryOfOrigin( "GBR" ); product1b.setFabricContent( "Cotton" ); product1b.setHarmonisedProductCode( "HCODE89761431" ); product1b.setProductCode( "SKU-873812" ); product1b.setProductDescription( "Mens shirts" ); product1b.setProductQuantity( 15 ); 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 ); Parcel parcel2 = new Parcel(); parcel2.setDutyPaid( 9.78 ); parcel2.setParcelWeight( 1.3 ); parcel2.setParcelDepth( 0.41 ); parcel2.setParcelHeight( 0.43 ); parcel2.setParcelWidth( 0.17 ); parcel2.setParcelValue( 15.99 ); parcel1.setProducts( new Product[] { product1a , product1b } ); parcel2.setProducts( new Product[] { product1b } ); consignment.setParcelCount( 2 ); consignment.setParcels( new Parcel[] { parcel1 , parcel2 } ); consignment.setConsignmentWeight( 4.53 ); consignment.setConsignmentValue( 200.00 ); AllocationService allocationService = createAllocationService(); ConsignmentService consignmentService = createConsignmentService(); Consignment[] createdConsignments = allocationService.createAndAllocateConsignments( new Consignment[] { consignment } , null ); for( Consignment c : createdConsignments ) { Labels labels = consignmentService.createPdfsForConsignments( new String[] { c.getConsignmentCode() } ); byte[] decodedData; FileOutputStream stream; decodedData = Base64.decode( labels.getLabelsPdf() ); stream = new FileOutputStream( "c:\\labels.pdf" ); stream.write( decodedData ); stream.flush(); stream.close(); if( labels.getDocumentsPdf() == null ) { System.out.println( "No A4 documentation to print" ); } else { decodedData = Base64.decode( labels.getDocumentsPdf() ); stream = new FileOutputStream( "c:\\a4_documents.pdf" ); stream.write( decodedData ); stream.flush(); stream.close(); } } } public static void main(String[] args ){ Example65 ex = new Example65(); try { ex.run(); } catch( Exception e ) { e.printStackTrace(); } } }

