// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the ContactService.
ContactServiceInterface contactService =
user.getService(DfpService.V201311.CONTACT_SERVICE);
// Set the IDs of the companies for the contacts.
Long advertiserCompanyId = Long.parseLong("INSERT_ADVERTISER_COMPANY_ID_HERE");
Long agencyCompanyId = Long.parseLong("INSERT_AGENCY_COMPANY_ID_HERE");
// Create an advertiser contact.
Contact advertiserContact = new Contact();
advertiserContact.setName("Mr. Advertiser #" + new Random().nextLong());
advertiserContact.setEmail("advertiser@advertising.com");
advertiserContact.setCompanyId(advertiserCompanyId);
// Create an agency contact.
Contact agencyContact = new Contact();
agencyContact.setName("Ms. Agency #" + new Random().nextLong());
agencyContact.setEmail("agency@agencies.com");
agencyContact.setCompanyId(agencyCompanyId);
// Create the contacts on the server.
Contact[] contacts =
contactService.createContacts(new Contact[] {advertiserContact, agencyContact});
for (Contact contact : contacts) {
System.out.printf("A contact with ID \"%d\" and name \"%s\" was created.\n",
contact.getId(), contact.getName());
}