You cannot use JailBreakMe method to jailbreak and unlock iOS 4.0.2 on iPhone 3G. However you can still jailbreak and unlock iPhone 3G using redsn0w. Here are the instructions:
Download the latest RedSn0w 0.9.5-b5 in our utilities page here.
Run RedSn0w and point it at the 4.0 IPSW. (Yes – point it at the 4.0 IPSW even though you're at 4.0.2). This will also hacktivate your iPhone3G at 4.0.1 if you haven't already been activated by iTunes.
If you need a carrier unlock - install ultrasn0w in Cydia (add repository http://repo666.ultrasn0w.com). For T-Mobile in the USA remember to turn off 3G mode in Settings→General→Network.