}
public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, long campaignId) throws Exception {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService =
adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group.
AdGroup adGroup = new AdGroup();
adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
adGroup.setStatus(AdGroupStatus.ENABLED);
adGroup.setCampaignId(campaignId);
// Create ad group bid.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpmBid bid = new CpmBid();
bid.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration.setBids(new Bids[] {bid});
adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Add as many additional ad groups as you need.
AdGroup adGroup2 = new AdGroup();
adGroup2.setName("Earth to Venus Cruises #" + System.currentTimeMillis());
adGroup2.setStatus(AdGroupStatus.ENABLED);
adGroup2.setCampaignId(campaignId);
BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
CpmBid bid2 = new CpmBid();
bid2.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration2.setBids(new Bids[] {bid2});
adGroup2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
// Create operations.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.ADD);
AdGroupOperation operation2 = new AdGroupOperation();
operation2.setOperand(adGroup2);
operation2.setOperator(Operator.ADD);
AdGroupOperation[] operations = new AdGroupOperation[] {operation, operation2};
// Add ad groups.
AdGroupReturnValue result = adGroupService.mutate(operations);
// Display new ad groups.
for (AdGroup adGroupResult : result.getValue()) {
System.out.println("Ad group with name \"" + adGroupResult.getName() + "\" and id \""
+ adGroupResult.getId() + "\" was added.");