// Get AdWordsUser from "~/adwords.properties".
AdWordsUser user = new AdWordsUser();
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
user.getService(AdWordsService.V201309.ADGROUP_CRITERION_SERVICE);
long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
// Create biddable ad group criterion for gender
Gender genderTarget = new Gender();
genderTarget.setId(ID_FOR_MALE);
BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
genderBiddableAdGroupCriterion.setCriterion(genderTarget);
// Create negative ad group criterion for age range
AgeRange ageRangeNegative = new AgeRange();
ageRangeNegative.setId(ID_FOR_18_TO_24);
NegativeAdGroupCriterion ageRangeNegativeAdGroupCriterion = new NegativeAdGroupCriterion();
ageRangeNegativeAdGroupCriterion.setAdGroupId(adGroupId);
ageRangeNegativeAdGroupCriterion.setCriterion(ageRangeNegative);
// Create operations.
AdGroupCriterionOperation genderBiddableAdGroupCriterionOperation =
new AdGroupCriterionOperation();
genderBiddableAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
genderBiddableAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation ageRangeNegativeAdGroupCriterionOperation =
new AdGroupCriterionOperation();
ageRangeNegativeAdGroupCriterionOperation.setOperand(ageRangeNegativeAdGroupCriterion);
ageRangeNegativeAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {
genderBiddableAdGroupCriterionOperation, ageRangeNegativeAdGroupCriterionOperation};
// Add ad group criteria.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display ad group criteria.
if (result != null && result.getValue() != null) {
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
System.out.println("Ad group criterion with ad group id \""