It depends mostly on luck. Buy about 30 Ultra Balls, and a few Timer balls to use after you run out of Ultra Balls, if you get really unlucky.
Also, bring Pokemon with Spore/Thunder Wave/False Swipe (to make sure it only has 1 HP left, don't use it the entire battle).
mewtworaiser, those "codes" don't really help at all.