private static final String AGENCY_ID = "INSERT_AGENCY_COMPANY_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
long advertiserCompanyId, long agencyCompanyId) throws Exception {
// Get the ContactService.
ContactServiceInterface contactService =
dfpServices.get(session, ContactServiceInterface.class);
// Create an advertiser contact.
Contact advertiserContact = new Contact();
advertiserContact.setName("Mr. Advertiser #" + new Random().nextInt(Integer.MAX_VALUE));
advertiserContact.setEmail("advertiser@advertising.com");
advertiserContact.setCompanyId(advertiserCompanyId);
// Create an agency contact.
Contact agencyContact = new Contact();
agencyContact.setName("Ms. Agency #" + new Random().nextInt(Integer.MAX_VALUE));
agencyContact.setEmail("agency@agencies.com");
agencyContact.setCompanyId(agencyCompanyId);
// Create the contacts on the server.
Contact[] contacts =
contactService.createContacts(new Contact[] {advertiserContact, agencyContact});
for (Contact createdContact : contacts) {
System.out.printf("A contact with ID \"%d\" and name \"%s\" was created.\n",
createdContact.getId(), createdContact.getName());
}