Example 16 : Producing labels for a consignment

Printer-friendly version

  This will produce a single PDF file containing the labels for a specific consignment. Each label appears on a separate page.

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 label 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 Example16 extends ExampleBase {
 
	public void run() throws Exception {
		ConsignmentService service = createConsignmentService();
 
		String encodedPdfDocument = service.createLabelsAsPdf( "DMC01V00M08M" );
 
		byte[] rawData = Base64.decode( encodedPdfDocument );
 
		FileOutputStream stream = new FileOutputStream( "c:\\labels.pdf" );
		stream.write( rawData );
		stream.flush();
		stream.close();
 
	}
}