Before writing APEX code, please install the ShipAutomate package here. (sandbox)

Bulk Shipments

// collect record ids
Id prefId = 'a0258000001ivGi'; // a0258000001ivGi - 418316874 DHLExpress
Id contactId = '00358000006wy1I'; // Jack Rodgers

zkmulti__MCShipmate_Preference__c shipmatePref = [
SELECT Id, Name,
zkmulti__Carrier__c, zkmulti__Label_Image_Type_Default__c,
zkmulti__Billing_City__c, zkmulti__Billing_Country__c, zkmulti__Billing_State__c,
zkmulti__Billing_Street__c, zkmulti__Billing_Zip_Postal_Code__c, zkmulti__Company_Name__c, zkmulti__Sender_Email_Default__c, zkmulti__Sender_Name_Default__c,
zkmulti__Sender_Phone_Default__c, zkmulti__Shipping_City__c, zkmulti__Shipping_Country__c, zkmulti__Shipping_Is_Residential__c,
zkmulti__Shipping_State__c, zkmulti__Shipping_Street__c, zkmulti__Shipping_Zip_Postal_Code__c, zkmulti__Currency_Default__c
FROM zkmulti__MCShipmate_Preference__c
WHERE Id = :prefId];

// 1. zkmulti__MCBulk_Shipment__c object
zkmulti__MCBulk_Shipment__c bulkShipment = new zkmulti__MCBulk_Shipment__c (
zkmulti__Shipmate_Preference__c = shipmatePref.Id
);
insert bulkShipment;

// get contact information
Contact con = [
SELECT MailingCity, Account.Name, MailingCountry,
 Email, FirstName, LastName,
Phone, MailingState, MailingStreet,
  MailingPostalCode
FROM Contact
WHERE Id = :contactId];

// 2. zkmulti__MCQueued_Shipment__c object
List<zkmulti__MCQueued_Shipment__c> queuedShipmentsToInsert = new List<zkmulti__MCQueued_Shipment__c>();

zkmulti__MCQueued_Shipment__c queuedShipment = new zkmulti__MCQueued_Shipment__c (
zkmulti__Bulk_Shipment__c = bulkShipment.Id,
zkmulti__Carrier__c = shipmatePref.zkmulti__Carrier__c, // from pref
zkmulti__Currency__c = 'USD',
zkmulti__Label_Image_Type__c = shipmatePref.zkmulti__Label_Image_Type_Default__c,
zkmulti__Service_Type__c = 'Express1030NonDoc', // TODO
zkmulti__Package_Type__c = 'JumboParcel',  // TODO
zkmulti__Dimension_Units__c = 'IN',
zkmulti__Weight_Units__c = 'LB',

// sender info
zkmulti__Sender_Name__c = shipmatePref.zkmulti__Sender_Name_Default__c,
zkmulti__Sender_Address_is_Residential__c = false,
zkmulti__Sender_City__c = shipmatePref.zkmulti__Shipping_City__c,
zkmulti__Sender_Company__c = shipmatePref.zkmulti__Company_Name__c,
zkmulti__Sender_Country__c = shipmatePref.zkmulti__Shipping_Country__c,
zkmulti__Sender_Email__c = shipmatePref.zkmulti__Sender_Email_Default__c,
zkmulti__Sender_Phone__c = shipmatePref.zkmulti__Sender_Phone_Default__c,
zkmulti__Sender_State_Province__c = shipmatePref.zkmulti__Shipping_State__c,
zkmulti__Sender_Street__c = shipmatePref.zkmulti__Shipping_Street__c,
zkmulti__Sender_Zip_Postal_Code__c = shipmatePref.zkmulti__Shipping_Zip_Postal_Code__c,

// recipient info
zkmulti__Recipient_Address_is_Residential__c = false,
zkmulti__Recipient_City__c = con.MailingCity,
zkmulti__Recipient_Company__c = con.Account.Name,
zkmulti__Recipient_Country__c = con.MailingCountry,
zkmulti__Recipient_Email__c = con.Email,
zkmulti__Recipient_Name__c = con.FirstName + ' ' + con.LastName,
zkmulti__Recipient_Phone__c = con.Phone,
zkmulti__Recipient_State_Province__c = con.MailingState,
// zkfedex__RecipientState__c = 'London',
zkmulti__Recipient_Street__c = con.MailingStreet,
zkmulti__Recipient_Zip_Postal_Code__c = con.MailingPostalCode,

zkmulti__Payment_Type__c = 'Sender'
);
insert queuedShipment;

queuedShipmentsToInsert.add(queuedShipment);

// 3. zkmulti__MCQueued_Package__c object
List<zkmulti__MCQueued_Package__c> queuedPackagesToInsert = new List<zkmulti__MCQueued_Package__c>();

for (zkmulti__MCQueued_Shipment__c qs : queuedShipmentsToInsert) {
zkmulti__MCQueued_Package__c queuedPackage = new zkmulti__MCQueued_Package__c (
zkmulti__Height__c = 1,
zkmulti__Length__c = 2,
zkmulti__Width__c = 3,
zkmulti__Weight__c = 1,
zkmulti__Weight_Units__c = 'LB',
zkmulti__Dimension_Units__c = 'IN',
zkmulti__Packaging_Type__c = 'JumboParcel',
zkmulti__Queued_Shipment__c = qs.Id          
);
queuedPackagesToInsert.add(queuedPackage);
}

insert queuedPackagesToInsert;

// 4. zkmulti__MCQueued_Customs_Item__c object
List<zkmulti__MCQueued_Customs_Item__c> customItemsToInsert = new List<zkmulti__MCQueued_Customs_Item__c>();

for (zkmulti__MCQueued_Shipment__c qs : queuedShipmentsToInsert) {
zkmulti__MCQueued_Customs_Item__c queuedPackage = new zkmulti__MCQueued_Customs_Item__c (
zkmulti__Weight__c = 1,
zkmulti__Weight_Units__c = 'LB',
zkmulti__Country_of_Manufacture__c = 'US',
zkmulti__Harmonized_Code__c = '1234567',
zkmulti__Quantity__c = 1,
zkmulti__Value__c = 5,
zkmulti__Value_Currency__c = 'USD',
zkmulti__Description__c = 'Description',
zkmulti__Queued_Shipment__c = qs.Id          
);
customItemsToInsert.add(queuedPackage);
}

insert customItemsToInsert;


// validation
// String batchId = zkmulti.BulkShipmentInterface.validateBulkShipment(bulkShipment.Id, false);
String batchId = zkmulti.BulkShipmentInterface.processBulkShipment(bulkShipment.Id);
System.debug('BATCH ID :' + batchId);
Did this answer your question?