Multiple Package Returns for UPS and Auto Printing

This weeks post will detail how to achieve the following using our package, and some apex code.

  • Multiple Package Returns for UPS
  • Auto Printing

Multiple Package Returns for UPS

Currently the UPS api only allows the creation of 1 return label at a time. So if you want to create 20 return labels at once you need to set up a batch process to create them individually but group them into a Bulk Shipment which then allows you to print them all off at once.

We first need a method to create our bulk shipments, which we then reference later on in a loop.

Line 2: create a new queuedShipment object.

Line 3: set this new queuedShipment to be in the bulkShipment object.

Line 4-9: Sets the payment type, service type, units, labeltype, packaging type and the account this shipment is related to.

Lines 12-20: sets the sender address from the shipping preference.

Lines 23-30: set the recipient address details from the account.

Liens 33-35: set the values needed to create a return shipment.

Then we utilise a loop for the number of labels we will be creating. The code to loop through and to eventually send the shipments to be created is here:

Line 5: Create the bulkShipmentId that we will then send for processing after we have created the queuedShipments

Lines 10-21: This is the for loop where we go through creating the list of queuedShipments and creating the packages that are also required.

Line 28: is where we send the bulkShipment to be processed.

Lines 44-55: show how to create the packages.

Auto Printing

Our package is already setup to auto print a shipment label and all related documents from the shipment view page. All you need is the salesforce id of the shipment that has been generated. After shipment creation, you need to redirect the user to the shipment using the code below, and as long as you have setup the users default printers in the “Manage Printers”, the printing of all the labels and documents related to that shipment will automatically print on the respective printers. For example if you have a thermal shipping label and an international document, they will be printed to the thermal printer and to the laser printer respectively.

String redirectUrl = ‘/apex/zkups__ShipmentViewV2?autoprint=1&id=’ & shipmentId;

Any questions, please contact us and we will be happy to help you out.

You may also like...