Example 17 : Producing additional documentation for a consignment

Printer-friendly version

  This will produce a single PDF file containing the additional documentation for a specific consignment that need printing out on an A4 printer.

I've used the Apache Xerces' base-64 decoder to convert the SOAP response back into binary.

I've streamed the result to a file in this example, but that need not be the case in your solution. To get the document to actually print, one could pass it to Adobe Acrobat Reader on the command line or, if you're in .NET, you could make use of an ActiveX component instead.

package com.metapack.dm.test;
 
import java.io.FileOutputStream;
 
import com.metapack.deliverymanager.client.webservices.ConsignmentService;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
 
public class Example17 extends ExampleBase {
 
	public void run() throws Exception {
		ConsignmentService service = createConsignmentService();
 
		String encodedPdfDocument = service.createDocumentationAsPdf( "DMC01V00M08M" );
 
		if( encodedPdfDocument == null ) {
			System.out.println( "There is no additional documentation to print for this consignment" );
		} else {
			byte[] rawData = Base64.decode( encodedPdfDocument );
			FileOutputStream stream = new FileOutputStream( "c:\\a4_documentation.pdf" );
			stream.write( rawData );
			stream.flush();
			stream.close();
		}
	}
}